package com.example.mydataaccesssample;

import android.os.Bundle;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class ActMain extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.actmain);
		InitialComponent();
	}

	OnClickListener btnShared_click=new OnClickListener(){
		public void onClick(View arg0) {
			
			Intent intent =new Intent(ActMain.this,ActSqlite.class);
			startActivity(intent);
	}};
	

	
	OnClickListener myBtnShared_click=new OnClickListener(){
		public void onClick(View arg0) {
			
			SharedPreferences table = getSharedPreferences("T1", 0);
			Editor editor=table.edit();
			editor.putString("KK", txtDate.getText().toString()).commit();
			editor.putString("II", txtWaitTask.getText().toString()).commit();
			
			Toast.makeText(ActMain.this, "儲存資料成功", Toast.LENGTH_SHORT).show();
	}};
	
	OnClickListener btnReload_click=new OnClickListener(){
		public void onClick(View arg0) {
			SharedPreferences table = getSharedPreferences("T1", 0);
			txtDate.setText(table.getString("KK","default text"));
			txtWaitTask.setText(table.getString("II","default text2"));

	}};
	
	OnClickListener btnToDo_click=new OnClickListener(){
		public void onClick(View arg0) {
			
			Intent intent =new Intent(ActMain.this,ActToDo.class);
			startActivity(intent);
	}};
	
	OnClickListener btnFile_click=new OnClickListener(){
		public void onClick(View arg0) {
			
			Intent intent =new Intent(ActMain.this,ActFile.class);
			startActivity(intent);
	}};
	
	
	private void InitialComponent() {
		
		
		btnShared=(Button)findViewById(R.id.btnShared);
		btnShared.setOnClickListener(btnShared_click);
		
		
		btnFile=(Button)findViewById(R.id.btnFile);
		btnFile.setOnClickListener(btnShared_click);
		btnSQLite=(Button)findViewById(R.id.btnSQLite);
		btnSQLite.setOnClickListener(btnShared_click);
		
		btnAdd =(Button)findViewById(R.id.btnAdd);
		btnAdd.setOnClickListener(myBtnShared_click);
		
		btnReload = (Button)findViewById(R.id.btnReload);
		btnReload.setOnClickListener(btnReload_click);
		
		btnToDo = (Button)findViewById(R.id.btnToDo);
		btnToDo.setOnClickListener(btnToDo_click);
		
		viewDate=(TextView)findViewById(R.id.viewDate);
		viewWaitTask=(TextView)findViewById(R.id.viewWaitTask);
		
		txtDate = (EditText)findViewById(R.id.txtDate);
		txtWaitTask = (EditText)findViewById(R.id.txtWaitTask);
		
		btnFile = (Button)findViewById(R.id.btnFile);
		btnFile.setOnClickListener(btnFile_click);
	}
	
    
	Button btnShared=null;
	Button btnFile=null;
	Button btnSQLite=null;
	Button btnAdd =null;
	Button btnReload = null;
	Button btnToDo = null;
	
	TextView viewDate = null;
	TextView viewWaitTask = null;
	
	EditText txtDate=null;
	EditText txtWaitTask=null;
}
